home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / drivers.arc / TERMIN.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-10-20  |  3.8 KB  |  184 lines

  1. ;*  Russell Nelson, Clarkson University.  October 20, 1988
  2. ;*  Portions (C) Copyright 1988 Russell Nelson
  3. ;*
  4. ;*  Permission is granted to any individual or institution to use, copy,
  5. ;*  modify, or redistribute this software and its documentation provided
  6. ;*  this notice and the copyright notices are retained.  This software may
  7. ;*  not be distributed for profit, either in original form or in derivative
  8. ;*  works.  Russell Nelson makes no representations about the suitability
  9. ;*  of this software for any purpose.  RUSSELL NELSON GIVES NO WARRANTY,
  10. ;*  EITHER EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION
  11. ;*  PROVIDED, INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY
  12. ;*  AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  13. ;*/
  14.  
  15.  
  16. segmoffs    struc
  17. offs        dw    ?
  18. segm        dw    ?
  19. segmoffs    ends
  20.  
  21. HT    equ    09h
  22. CR    equ    0dh
  23. LF    equ    0ah
  24.  
  25. code    segment byte public
  26.     assume    cs:code, ds:code
  27.  
  28.     org    80h
  29. phd_dioa    label    byte
  30.  
  31.     org    100h
  32. start:
  33.     jmp    start_1
  34.  
  35. their_isr    dd    ?
  36. packet_int_no    db    ?,?
  37. signature    db    'PKT DRVR',0
  38. signature_len    equ    $-signature
  39. no_signature_msg    db    "No packet driver at that address",'$'
  40. usage_msg    db    "usage: termin <packet_int_no>",'$'
  41.  
  42. usage_error:
  43.     mov    dx,offset usage_msg
  44. error:
  45.     mov    ah,9
  46.     int    21h
  47.     int    20h
  48.  
  49. start_1:
  50.     mov    si,offset phd_dioa+1
  51.     cmp    byte ptr [si],CR    ;end of line?
  52.     je    usage_error
  53.  
  54.     mov    di,offset packet_int_no
  55.     call    get_number
  56.  
  57.     mov    ah,35h            ;get their packet interrupt.
  58.     mov    al,packet_int_no
  59.     int    21h
  60.     mov    their_isr.offs,bx
  61.     mov    their_isr.segm,es
  62.  
  63.     lea    di,3[bx]
  64.     mov    si,offset signature
  65.     mov    cx,signature_len
  66.     repe    cmpsb
  67.     jne    no_signature_err
  68.  
  69.     mov    ah,5            ;terminate the driver.
  70.     mov    bx,0
  71.     pushf
  72.     cli
  73.     call    their_isr
  74.  
  75.     int    20h
  76.  
  77. no_signature_err:
  78.     mov    dx,offset no_signature_msg
  79.     mov    ah,9
  80.     int    21h
  81.     int    20h
  82.  
  83.  
  84.     public    get_number
  85. get_number:
  86.     mov    bp,10            ;we default to 10.
  87.     jmp    short get_number_0
  88.  
  89.     public    get_hex
  90. get_hex:
  91.     mov    bp,16
  92. ;get a hex number from [si], skipping leading blanks.
  93. ;return cy if there are no digits at all.
  94. ;return nc, bx:cx = number, and store cx at [di]
  95. get_number_0:
  96.     call    skip_blanks
  97.     call    get_digit        ;is there really a number here?
  98.     jc    get_number_3
  99.     or    al,al            ;Does the number begin with zero?
  100.     jne    get_number_4        ;no.
  101.     mov    bp,8            ;yes - they want octal.
  102. get_number_4:
  103.  
  104.     xor    cx,cx            ;get a hex number.
  105.     xor    bx,bx
  106. get_number_1:
  107.     lodsb
  108.     cmp    al,'x'            ;did they really want hex?
  109.     je    get_number_5        ;yes.
  110.     cmp    al,'X'            ;did they really want hex?
  111.     je    get_number_5        ;yes.
  112.     call    get_digit        ;convert a character into an int.
  113.     jc    get_number_2        ;not a digit (neither hex nor dec).
  114.     xor    ah,ah
  115.     cmp    ax,bp            ;larger than our base?
  116.     jae    get_number_2        ;yes.
  117.  
  118.     push    ax            ;save the new digit.
  119.  
  120.     mov    ax,bp            ;multiply the low word by ten.
  121.     mul    cx
  122.     mov    cx,ax            ;keep the low word.
  123.     push    dx            ;save the high word for later.
  124.     mov    ax,bp
  125.     mul    bx
  126.     mov    bx,ax            ;we keep only the low word (which is our high word)
  127.     pop    dx
  128.     add    bx,ax            ;add the high result from earlier.
  129.  
  130.     pop    ax            ;get the new digit back.
  131.     add    cx,ax            ;add the new digit in.
  132.     adc    bx,0
  133.     jmp    get_number_1
  134. get_number_5:
  135.     mov    bp,16            ;change the base to hex.
  136.     jmp    get_number_1
  137. get_number_2:
  138.     dec    si
  139.     mov    [di],cx            ;store the parsed number.
  140.     clc
  141.     ret
  142. get_number_3:
  143.     stc
  144.     ret
  145.  
  146.  
  147.     public    skip_blanks
  148. skip_blanks:
  149.     lodsb                ;skip blanks.
  150.     cmp    al,' '
  151.     je    skip_blanks
  152.     cmp    al,HT
  153.     je    skip_blanks
  154.     dec    si
  155.     ret
  156.  
  157.  
  158. get_digit:
  159. ;enter with al = character
  160. ;return nc, al=digit, or cy if not a digit.
  161.     cmp    al,'0'            ;decimal digit?
  162.     jb    get_digit_1        ;no.
  163.     cmp    al,'9'            ;. .?
  164.     ja    get_digit_2        ;no.
  165.     sub    al,'0'
  166.     clc
  167.     ret
  168. get_digit_2:
  169.     or    al,20h
  170.     cmp    al,'a'            ;hex digit?
  171.     jb    get_digit_1
  172.     cmp    al,'f'            ;hex digit?
  173.     ja    get_digit_1
  174.     sub    al,'a'-10
  175.     clc
  176.     ret
  177. get_digit_1:
  178.     stc
  179.     ret
  180.  
  181. code    ends
  182.  
  183.     end    start
  184.